package org.example;

import org.example.controller.*;
import org.example.entry.UserInfo;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created with IntelliJ IDEA 2023.
 * Description:
 * User: homechen
 * Date: 2024-03-26
 * Time: 13:45
 */
// 获取Bean
public class TestMain {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");

        BeanLifeController controller = context.getBean("beanLife", BeanLifeController.class);
        controller.use();
        context.destroy(); // 销毁

//        ScopeController controller = context.getBean("scopeController", ScopeController.class);
//        controller.doController();
//
//        System.out.println("=====================");
//        ScopeController2 controller2 = context.getBean("scopeController2", ScopeController2.class);
//        controller2.doController();


//        UserRespository userRespository = context.getBean("userRespository", UserRespository.class);
//        userRespository.doRespository();
//        UserController userController =
//                context.getBean("userController", UserController.class);  // 小驼峰 + 类名
//        userController.doUserController();

//        UController uController = context.getBean("UController", UController.class);
//        userController.doUserController();
//
//        UserInfo userInfo = context.getBean("user2", UserInfo.class);
//        System.out.println("userInfoId: " + userInfo.getId());
//        System.out.println("userInfoName: " + userInfo.getName());
        // 获取 spring 的上下文
//        ApplicationContext context = new
//                ClassPathXmlApplicationContext("spring-config.xml");
//        // 从上下文中获取 bean
//        User user = (User) context.getBean("user"); // 根据bean id 获取
//
//        // 使用 bean
//        user.doUser();
    }
}
